package top.tangyh.lamp.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class StringCommon {

    public static  String getItemCode(Integer inputType){
        //                    WHEN b.input_type = 1
//                    THEN 'in_jmrl'
//                    WHEN b.input_type = 2
//                    THEN 'in_kfywrl'
//                    WHEN b.input_type = 3
//                    THEN 'in_bsl'
//                    WHEN b.input_type = 4
//                    THEN 'in_qt'
//                    WHEN b.input_type = 5
//                    THEN 'in_kf'
//                    WHEN b.input_type = 6
//                    THEN 'in_sxzpl'
//                    WHEN b.input_type = 7
//                    THEN 'in_hl7sxzpl'
        if(inputType==1){
            return "in_jmrl";
        }else if(inputType==2){
            return "in_kfywrl";
        }else if(inputType==3){
            return "in_bsl";
        }else if(inputType==4){
            return "in_qt";
        }else if(inputType==5){
            return "in_kf";
        }else if(inputType==6){
            return "in_sxzpl";
        }else if(inputType==7){
            return "in_hl7sxzpl";
        }
        return "null";
    }


    public static LocalDateTime getTimeByExeTime(Date exeTime) {

        Instant instant = exeTime.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        //获取指定时间的年月日时分秒
        int year = localDateTime.getYear();
        Month month = localDateTime.getMonth();
        int hour = localDateTime.getHour();
        int minute = localDateTime.getMinute();
        int second = localDateTime.getSecond();
        //-----------------------------------
        if (second == 0 && minute == 0) {
            return localDateTime;
        } else {
            localDateTime = localDateTime.plusHours(1);
            DateTimeFormatter fmtDate = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");
            String dateStr = localDateTime.format(fmtDate);
            dateStr = dateStr + ":00:00";
            DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime time = LocalDateTime.parse(dateStr, fmt);
            return time;
        }

    }

    public static void main(String[] args) {

        String str = "2023-02-24 17:00:00";

        Date datea = StrToDate(str);


        LocalDateTime time = getTimeByExeTime(datea);
        DateTimeFormatter fmt24 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateStr24 = time.format(fmt24);
        System.out.println(dateStr24);
    }

    public static Date StrToDate(String str) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}